<template>
  <li
    @mouseenter="isFocus = true"
    @mouseleave="isFocus = false"
    :class="isFocus ? 'active' : ''"
  >
    <label>
      <input type="checkbox" :checked="done" @change="updateSingleHandler" />
      <span>{{ todo }}</span>
    </label>
    <button
      class="btn btn-danger"
      :style="{ display: isFocus ? 'block' : 'none' }"
      @click="deleteHandler"
    >
      删除
    </button>
  </li>
</template>

<script>
export default {
  name: "Item",
  props: ["id", "todo", "done"],
  data() {
    return {
      isFocus: false,
    };
  },
  methods: {
    // 单个删除
    deleteHandler() {
      // 调用自定义addTodoList事件，并传递参数newTodo
      this.$bus.$emit("deleteSingleById", this.id);
    },
    // 单个修改
    updateSingleHandler() {
      this.$bus.$emit("updateSingleDoneById", this.id);
    },
  },
};
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
.active {
  background: hotpink;
}
</style>